package com.ruoyi.web.controller.basic;

import java.util.List;

import com.ruoyi.basic.domain.TbDailyUnitPrice;
import com.ruoyi.basic.domain.TbMonthlyExchangeRate;
import com.ruoyi.basic.service.ITbMonthlyExchangeRateService;
import com.ruoyi.price.domain.TbProject;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 汇率Controller
 * 
 * @author ruoyi
 * @date 2022-10-26
 */
@Controller
@RequestMapping("/basic/monthly/rate")
public class TbMonthlyExchangeRateController extends BaseController
{
    private String prefix = "basic/monthly/rate";

    @Autowired
    private ITbMonthlyExchangeRateService tbMonthlyExchangeRateService;

    @RequiresPermissions("basic:monthly:rate:view")
    @GetMapping()
    public String rate()
    {
        return prefix + "/rate";
    }

    /**
     * 查询汇率列表
     */
    @RequiresPermissions("basic:monthly:rate:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbMonthlyExchangeRate tbMonthlyExchangeRate)
    {
        startPage();
        List<TbMonthlyExchangeRate> list = tbMonthlyExchangeRateService.listByCondition(tbMonthlyExchangeRate);
        return getDataTable(list);
    }

    /**
     * 导出汇率列表
     */
    @RequiresPermissions("basic:monthly:rate:export")
    @Log(title = "汇率", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbMonthlyExchangeRate tbMonthlyExchangeRate)
    {
        List<TbMonthlyExchangeRate> list = tbMonthlyExchangeRateService.listByCondition(tbMonthlyExchangeRate);
        ExcelUtil<TbMonthlyExchangeRate> util = new ExcelUtil<TbMonthlyExchangeRate>(TbMonthlyExchangeRate.class);
        return util.exportExcel(list, "汇率数据");
    }

    /**
     * 新增汇率
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存汇率
     */
    @RequiresPermissions("basic:monthly:rate:add")
    @Log(title = "汇率", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbMonthlyExchangeRate tbMonthlyExchangeRate)
    {
        return toAjax(tbMonthlyExchangeRateService.saveRate(tbMonthlyExchangeRate));
    }

    /**
     * 修改汇率
     */
    @RequiresPermissions("basic:monthly:rate:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbMonthlyExchangeRate tbMonthlyExchangeRate = tbMonthlyExchangeRateService.getById(id);
        mmap.put("tbExchangeRate", tbMonthlyExchangeRate);
        return prefix + "/edit";
    }

    /**
     * 修改保存汇率
     */
    @RequiresPermissions("basic:monthly:rate:edit")
    @Log(title = "汇率", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbMonthlyExchangeRate tbMonthlyExchangeRate)
    {
        return toAjax(tbMonthlyExchangeRateService.updateRate(tbMonthlyExchangeRate));
    }

    /**
     * 删除汇率
     */
    @RequiresPermissions("basic:monthly:rate:remove")
    @Log(title = "汇率", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbMonthlyExchangeRateService.deleteByIds(ids));
    }

    @PostMapping("/checkRateMonth")
    @ResponseBody
    public String checkRateMonth(TbMonthlyExchangeRate tbMonthlyExchangeRate)
    {
        return tbMonthlyExchangeRateService.checkRateMonth(tbMonthlyExchangeRate);
    }
}
